package edu.mama.college.service;

import edu.mama.college.mapper.UserStudyRecordMapper;
import edu.mama.college.model.UserStudyRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserStudyRecordService {

    @Autowired
    private UserStudyRecordMapper userStudyRecordMapper;

    /**
     * 跟新学习时长
     * @param userStudyRecord
     */
    public  void updateUserStudyRecord(UserStudyRecord userStudyRecord){
        userStudyRecordMapper.updateUserStudyRecord(userStudyRecord);
    }

    /**
     * 增加学习课程-学习章节
     * @param userStudyRecord
     */
    public void insertUserStudyRecord(UserStudyRecord userStudyRecord){
        userStudyRecordMapper.insertUserStudyRecord(userStudyRecord);
    }


    /**
     * 学习数据统计
     * @param userId
     * @return
     */
    public Map<String, Integer> statistic(int userId){
        Map<String,Integer> dataMap = new HashMap<>();
        dataMap.put("mins",userStudyRecordMapper.todayStudiedMins(userId));
        dataMap.put("days",userStudyRecordMapper.totalStudiedDays(userId));
        dataMap.put("courses",userStudyRecordMapper.studiedCourses(userId));
        return dataMap;
    }

    /**
     * 定时任务
     * @param userStudyRecordList
     */
    public void scheduleAdd(List<UserStudyRecord> userStudyRecordList){
        userStudyRecordMapper.scheduleAdd(userStudyRecordList);
    }


}
